namespace SmartSoft.Invoices
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.Controls.ChildGridControls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCCTLEditor : FormEditor
    {
        private IContainer components;
        private GridDetail grdDetail;
        private LabelControl lblDesc_EN;
        private LabelControl lblDia_Chi;
        private LabelControl lblDien_Giai;
        private LabelControl lblGhi_Chu;
        private LabelControl lblMa_Dt;
        private CTKHODataAccess oMethod;
        private TextControl txtDesc_EN;
        private TextControl txtDia_Chi;
        private TextControl txtDien_Giai;
        private TextControl txtGhi_Chu;
        private TextSearch txtMa_Dt;
        private TextControl txtTen_Dt;
        private TextControl txtTen_CvX;
        private TextSearch txtMa_CvX;
        private LabelControl lblMa_Cv;
        private TextControl txtTen_CvN;
        private TextSearch txtMa_CvN;
        private LabelControl lblMa_CvN;
        private TextControl txtTen_DtN;
        private TextSearch txtMa_DtN;
        private TextNumeric txtTTien;
        private LabelControl lblTTien_Nt0;
        private TextControl txtTen_BpX;
        private TextSearch txtMa_BpX;
        private LabelControl lblMa_BpX;
        private SearchColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private OptionColumn Column11;
        private DataGridViewTextBoxColumn Column23;
        private NumericColumn Column22;
        private NumericColumn Column1;
        private NumericColumn Column2;
        private LabelControl lblMa_DtN;

        public FormCCTLEditor()
        {
            this.oMethod = new CTKHODataAccess();
            this.InitializeComponent();
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            base.DetailGridBrowser.CellEndEdit += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEndEdit);
            base.ResizeForm();
        }

        public FormCCTLEditor(SSInvoiceLib po_SSInvoiceLib) : base(po_SSInvoiceLib)
        {
            this.oMethod = new CTKHODataAccess();
            this.InitializeComponent();
            base.InvoiceCode = po_SSInvoiceLib.InvoiceCode;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            base.DetailGridBrowser.CellEndEdit += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEndEdit);
            base.ResizeForm();
        }

        public FormCCTLEditor(string ps_InvoiceCode, string ps_MasterInvoiceOrder) : base(ps_InvoiceCode, ps_MasterInvoiceOrder)
        {
            this.oMethod = new CTKHODataAccess();
            this.InitializeComponent();
            base.InvoiceCode = ps_InvoiceCode;
            base.DetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEnter);
            base.DetailGridBrowser.CellEndEdit += new DataGridViewCellEventHandler(this.DetailGridBrowser_CellEndEdit);
            base.LocalMasterRow = this.oMethod.GetMasterDataRow(base.SavedMasterOrder);
            base.LocalDetailDataSet = this.oMethod.GetDetailDataSet(base.SavedMasterOrder);
            this.OnShow();
            base.ResizeForm();
        }

        private bool AddNewRow(bool pb_Inserted)
        {
            if ((base.DetailGridBrowser.CurrentRow == null) || (base.DetailGridBrowser.CurrentRow.DataBoundItem == null))
            {
                return false;
            }
            DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
            if ((((decimal) row["So_Luong9"]) == 0M) && (((decimal) row["So_Luong"]) == 0M))
            {
                return false;
            }
            int num = 0;
            if (pb_Inserted)
            {
                num = (int) row["Stt_Nv"];
                foreach (DataRow row2 in base.LocalDetailTable.Rows)
                {
                    if ((row2.RowState != DataRowState.Deleted) && (((int) row2["Stt_Nv"]) > num))
                    {
                        row2["Stt_Nv"] = ((int) row2["Stt_Nv"]) + 1;
                    }
                }
            }
            else
            {
                foreach (DataRow row3 in base.LocalDetailTable.Rows)
                {
                    if ((row3.RowState != DataRowState.Deleted) && (((int) row3["Stt_Nv"]) > num))
                    {
                        num = (int) row3["Stt_Nv"];
                    }
                }
                if (((int) row["Stt_Nv"]) < num)
                {
                    return false;
                }
            }
            object obj2 = row["Ma_Kho"];
            base.DetailGridBrowser.EndEdit();
            DataRow row4 = base.MakeDetailRow();
            int key = num + 1;
            row4["Stt_Nv"] = key;
            row4["He_So9"] = 1;
            row4["Ma_Kho"] = obj2;
            row4["So_Luong9"] = 0;
            row4["So_Luong"] = 0;
            row4["Gia"] = 0;
            row4["Tien"] = 0;
            row4["H_Luong"] = 0;
            row4["Do_Am_PT"] = 0;
            row4["Do_Con_PT"] = 0;
            base.LocalDetailTable.Rows.Add(row4);
            BindingSource dataSource = base.DetailGridBrowser.DataSource as BindingSource;
            dataSource.Position = dataSource.Find(base.DetailOrderString, key);
            return true;
        }

        private void Calculate()
        {
            DataRow row = ((DataRowView) this.grdDetail.CurrentRow.DataBoundItem).Row;
            row["So_Luong"] = decimal.Round(((decimal) row["So_Luong9"]) * ((decimal) row["He_So9"]), base.QuantityDecimals);
            
            if ( (decimal) row["Gia"] != 0)
            {
                row["Tien"] = decimal.Round(((decimal)row["So_Luong9"]) * ((decimal)row["Gia"]), base.LCAmountDecimals);
            }
            else
            {
                if ((decimal) row["So_luong9"] != 0)
                {
                    row["Gia"] = decimal.Round(((decimal)row["Tien"]) / ((decimal)row["So_Luong9"]), base.LCPriceDecimals);
                }
            }
        }

        private void DetailGridBrowser_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                this.SetItemRatio();
            }
            else if (e.ColumnIndex == 2)
            {
                this.SetItemRatio();
            }
            else if (e.ColumnIndex == 4)
            {
                this.Calculate();
                this.Sum();
            }
            else if (e.ColumnIndex == 5)
            {
                this.Calculate();
                this.Sum();
            }
            else if (e.ColumnIndex == 6)
            {
                this.Calculate();
                this.Sum();
            }
            else if (e.ColumnIndex == 7)
            {
                this.Calculate();
                this.Sum();
            }
        }

        private void DetailGridBrowser_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            //if (e.ColumnIndex == 2)
            //{
            //    this.SetItemUnits();
            //}
            //else if (e.ColumnIndex == 5)
            //{
            //    object obj2 = ((base.SSInvoiceParameters.InvoiceCode == "PWDC") && !string.IsNullOrEmpty(this.txtMa_KhoN.Text)) ? this.txtMa_KhoN.Value : SDBNull.Value;
            //    DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InvoicePosted = base.LocalMasterRow["Posted"];
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InvoiceDate = (DateTime) base.txtNgay_Ct.Value;
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).MasterKey = base.SavedMasterOrder;
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).DetailKey = base.SavedDetailOrder;
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InventoryCode = row["Ma_Kho"];
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InventoryInputCode = obj2;
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).RackNumber = row["Ma_Ke"];
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).LocalItemCode = row["Ma_Vt"];
            //    (base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).LocalDetailTable = base.LocalDetailTable;
            //}            
            if (e.ColumnIndex == 4)
            {
                this.SetItemUnits();
            }
            else if (e.ColumnIndex == 7)
            {
                //object obj2 = ((base.SSInvoiceParameters.InvoiceCode == "PWDC") && !string.IsNullOrEmpty(this.txtMa_KhoN.Text)) ? this.txtMa_KhoN.Value : SDBNull.Value;
                //DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InvoicePosted = base.LocalMasterRow["Posted"];
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InvoiceDate = (DateTime) base.txtNgay_Ct.Value;
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).MasterKey = base.SavedMasterOrder;
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).DetailKey = base.SavedDetailOrder;
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InventoryCode = row["Ma_Kho"];
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).InventoryInputCode = obj2;
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).RackNumber = row["Ma_Ke"];
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).LocalItemCode = row["Ma_Vt"];
                //(base.DetailGridBrowser.CurrentCell as SearchLotNumberCell).LocalDetailTable = base.LocalDetailTable;
            }


        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void grdDetail_CellBottomLeftLeaved(object sender, EventArgs e)
        {
            if (((base.DetailGridBrowser.Rows.Count == 1) || !string.IsNullOrEmpty(((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row["Ma_Vt"].ToString())) || !string.IsNullOrEmpty(base.ActiveControl.Text))
            {
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.NextCell;
            }
            else
            {
                this.txtGhi_Chu.Focus();
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.DeleteCurrentRow;
            }
        }

        private void grdDetail_CellRightLeaved(object sender, EventArgs e)
        {
            if (this.AddNewRow(false))
            {
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.FirstCell;
            }
            else
            {
                (base.DetailGridBrowser as GridDetail).UserMoveNextCell = GridDetail.MoveNextType.FirstCellNextRow;
            }
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCCTLEditor));
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
            this.txtDesc_EN = new SmartSoft.Controls.TextControl();
            this.txtDien_Giai = new SmartSoft.Controls.TextControl();
            this.lblDesc_EN = new SmartSoft.Controls.LabelControl();
            this.lblDien_Giai = new SmartSoft.Controls.LabelControl();
            this.txtDia_Chi = new SmartSoft.Controls.TextControl();
            this.txtTen_Dt = new SmartSoft.Controls.TextControl();
            this.txtMa_Dt = new SmartSoft.Controls.TextSearch();
            this.lblDia_Chi = new SmartSoft.Controls.LabelControl();
            this.lblMa_Dt = new SmartSoft.Controls.LabelControl();
            this.grdDetail = new SmartSoft.Controls.GridDetail();
            this.lblGhi_Chu = new SmartSoft.Controls.LabelControl();
            this.txtGhi_Chu = new SmartSoft.Controls.TextControl();
            this.txtTen_CvX = new SmartSoft.Controls.TextControl();
            this.txtMa_CvX = new SmartSoft.Controls.TextSearch();
            this.lblMa_Cv = new SmartSoft.Controls.LabelControl();
            this.txtTen_CvN = new SmartSoft.Controls.TextControl();
            this.txtMa_CvN = new SmartSoft.Controls.TextSearch();
            this.lblMa_CvN = new SmartSoft.Controls.LabelControl();
            this.txtTen_DtN = new SmartSoft.Controls.TextControl();
            this.txtMa_DtN = new SmartSoft.Controls.TextSearch();
            this.lblMa_DtN = new SmartSoft.Controls.LabelControl();
            this.txtTTien = new SmartSoft.Controls.TextNumeric();
            this.lblTTien_Nt0 = new SmartSoft.Controls.LabelControl();
            this.txtTen_BpX = new SmartSoft.Controls.TextControl();
            this.txtMa_BpX = new SmartSoft.Controls.TextSearch();
            this.lblMa_BpX = new SmartSoft.Controls.LabelControl();
            this.Column3 = new SmartSoft.Controls.ChildGridControls.SearchColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column11 = new SmartSoft.Controls.ChildGridControls.OptionColumn();
            this.Column23 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column22 = new SmartSoft.Controls.ChildGridControls.NumericColumn();
            this.Column1 = new SmartSoft.Controls.ChildGridControls.NumericColumn();
            this.Column2 = new SmartSoft.Controls.ChildGridControls.NumericColumn();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).BeginInit();
            this.SuspendLayout();
            // 
            // txtMa_Loai1
            // 
            this.txtMa_Loai1.TabIndex = 22;
            // 
            // txtMa_Loai2
            // 
            this.txtMa_Loai2.TabIndex = 23;
            // 
            // txtMa_Loai3
            // 
            this.txtMa_Loai3.TabIndex = 24;
            // 
            // txtNgay_Ct
            // 
            this.txtNgay_Ct.Location = new System.Drawing.Point(100, 53);
            // 
            // txtNgay_Ps
            // 
            this.txtNgay_Ps.Location = new System.Drawing.Point(100, 28);
            this.txtNgay_Ps.TabIndex = 0;
            // 
            // txtSo_Ct
            // 
            this.txtSo_Ct.TabIndex = 2;
            // 
            // txtDesc_EN
            // 
            this.txtDesc_EN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.txtDesc_EN.CheckTextSearched = false;
            this.txtDesc_EN.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtDesc_EN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDesc_EN.Location = new System.Drawing.Point(486, 161);
            this.txtDesc_EN.MaxLength = 254;
            this.txtDesc_EN.Name = "txtDesc_EN";
            this.txtDesc_EN.OldValue = null;
            this.txtDesc_EN.Size = new System.Drawing.Size(295, 20);
            this.txtDesc_EN.TabIndex = 18;
            this.txtDesc_EN.UserTextLength = SmartSoft.AppInstance.TextControlLength.InvoiceDescription;
            this.txtDesc_EN.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtDesc_EN.Value = ((object)(resources.GetObject("txtDesc_EN.Value")));
            // 
            // txtDien_Giai
            // 
            this.txtDien_Giai.CheckTextSearched = false;
            this.txtDien_Giai.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtDien_Giai.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDien_Giai.Location = new System.Drawing.Point(100, 162);
            this.txtDien_Giai.MaxLength = 254;
            this.txtDien_Giai.Name = "txtDien_Giai";
            this.txtDien_Giai.OldValue = null;
            this.txtDien_Giai.Size = new System.Drawing.Size(296, 20);
            this.txtDien_Giai.TabIndex = 17;
            this.txtDien_Giai.UserTextLength = SmartSoft.AppInstance.TextControlLength.InvoiceDescription;
            this.txtDien_Giai.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtDien_Giai.Value = ((object)(resources.GetObject("txtDien_Giai.Value")));
            // 
            // lblDesc_EN
            // 
            this.lblDesc_EN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.lblDesc_EN.AutoSize = true;
            this.lblDesc_EN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDesc_EN.Location = new System.Drawing.Point(409, 164);
            this.lblDesc_EN.Name = "lblDesc_EN";
            this.lblDesc_EN.Size = new System.Drawing.Size(71, 14);
            this.lblDesc_EN.TabIndex = 80;
            this.lblDesc_EN.Text = "Diễn giải (EN)";
            // 
            // lblDien_Giai
            // 
            this.lblDien_Giai.AutoSize = true;
            this.lblDien_Giai.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDien_Giai.Location = new System.Drawing.Point(13, 165);
            this.lblDien_Giai.Name = "lblDien_Giai";
            this.lblDien_Giai.Size = new System.Drawing.Size(73, 14);
            this.lblDien_Giai.TabIndex = 81;
            this.lblDien_Giai.Text = "Diễn giải (VN)";
            // 
            // txtDia_Chi
            // 
            this.txtDia_Chi.CheckTextSearched = false;
            this.txtDia_Chi.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtDia_Chi.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDia_Chi.Location = new System.Drawing.Point(100, 140);
            this.txtDia_Chi.MaxLength = 128;
            this.txtDia_Chi.Name = "txtDia_Chi";
            this.txtDia_Chi.OldValue = null;
            this.txtDia_Chi.Size = new System.Drawing.Size(295, 20);
            this.txtDia_Chi.TabIndex = 16;
            this.txtDia_Chi.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemDescription;
            this.txtDia_Chi.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtDia_Chi.Value = ((object)(resources.GetObject("txtDia_Chi.Value")));
            // 
            // txtTen_Dt
            // 
            this.txtTen_Dt.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Dt.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_Dt.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Dt.CheckTextSearched = false;
            this.txtTen_Dt.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Dt.Enabled = false;
            this.txtTen_Dt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Dt.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Dt.Location = new System.Drawing.Point(223, 100);
            this.txtTen_Dt.Name = "txtTen_Dt";
            this.txtTen_Dt.OldValue = null;
            this.txtTen_Dt.Size = new System.Drawing.Size(172, 13);
            this.txtTen_Dt.TabIndex = 9;
            this.txtTen_Dt.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtTen_Dt.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Dt.Value = ((object)(resources.GetObject("txtTen_Dt.Value")));
            // 
            // txtMa_Dt
            // 
            this.txtMa_Dt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Dt.CheckTextSearched = false;
            this.txtMa_Dt.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Dt.FieldDisplay = "Ten_Dt";
            this.txtMa_Dt.FirstFilter = "Is_Stop = \'1\'";
            this.txtMa_Dt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Dt.Location = new System.Drawing.Point(100, 96);
            this.txtMa_Dt.MaxLength = 32;
            this.txtMa_Dt.Name = "txtMa_Dt";
            this.txtMa_Dt.OldValue = null;
            this.txtMa_Dt.Size = new System.Drawing.Size(118, 20);
            this.txtMa_Dt.TabIndex = 8;
            this.txtMa_Dt.TableName = "DMDT";
            this.txtMa_Dt.TextDisplay = this.txtTen_Dt;
            this.txtMa_Dt.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Dt.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Dt.Value = ((object)(resources.GetObject("txtMa_Dt.Value")));
            this.txtMa_Dt.Validated += new System.EventHandler(this.txtMa_Dt_Validated);
            // 
            // lblDia_Chi
            // 
            this.lblDia_Chi.AutoSize = true;
            this.lblDia_Chi.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDia_Chi.Location = new System.Drawing.Point(13, 143);
            this.lblDia_Chi.Name = "lblDia_Chi";
            this.lblDia_Chi.Size = new System.Drawing.Size(40, 14);
            this.lblDia_Chi.TabIndex = 95;
            this.lblDia_Chi.Text = "Địa chỉ";
            // 
            // lblMa_Dt
            // 
            this.lblMa_Dt.AutoSize = true;
            this.lblMa_Dt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Dt.Location = new System.Drawing.Point(13, 99);
            this.lblMa_Dt.Name = "lblMa_Dt";
            this.lblMa_Dt.Size = new System.Drawing.Size(89, 14);
            this.lblMa_Dt.TabIndex = 94;
            this.lblMa_Dt.Text = "Người quyết định";
            // 
            // grdDetail
            // 
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column3,
            this.Column4,
            this.Column11,
            this.Column23,
            this.Column22,
            this.Column1,
            this.Column2});
            this.grdDetail.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdDetail.Location = new System.Drawing.Point(0, 184);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new System.Drawing.Size(794, 277);
            this.grdDetail.TabIndex = 19;
            this.grdDetail.CellRightLeaved += new System.EventHandler(this.grdDetail_CellRightLeaved);
            this.grdDetail.CellBottomLeftLeaved += new System.EventHandler(this.grdDetail_CellBottomLeftLeaved);
            // 
            // lblGhi_Chu
            // 
            this.lblGhi_Chu.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.lblGhi_Chu.AutoSize = true;
            this.lblGhi_Chu.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblGhi_Chu.Location = new System.Drawing.Point(12, 468);
            this.lblGhi_Chu.Name = "lblGhi_Chu";
            this.lblGhi_Chu.Size = new System.Drawing.Size(44, 14);
            this.lblGhi_Chu.TabIndex = 81;
            this.lblGhi_Chu.Text = "Ghi chú";
            // 
            // txtGhi_Chu
            // 
            this.txtGhi_Chu.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtGhi_Chu.CheckTextSearched = false;
            this.txtGhi_Chu.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtGhi_Chu.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtGhi_Chu.Location = new System.Drawing.Point(99, 465);
            this.txtGhi_Chu.MaxLength = 254;
            this.txtGhi_Chu.Name = "txtGhi_Chu";
            this.txtGhi_Chu.OldValue = null;
            this.txtGhi_Chu.Size = new System.Drawing.Size(455, 20);
            this.txtGhi_Chu.TabIndex = 20;
            this.txtGhi_Chu.UserTextLength = SmartSoft.AppInstance.TextControlLength.InvoiceDescription;
            this.txtGhi_Chu.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtGhi_Chu.Value = ((object)(resources.GetObject("txtGhi_Chu.Value")));
            // 
            // txtTen_CvX
            // 
            this.txtTen_CvX.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_CvX.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_CvX.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_CvX.CheckTextSearched = false;
            this.txtTen_CvX.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_CvX.Enabled = false;
            this.txtTen_CvX.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_CvX.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_CvX.Location = new System.Drawing.Point(610, 100);
            this.txtTen_CvX.Name = "txtTen_CvX";
            this.txtTen_CvX.OldValue = null;
            this.txtTen_CvX.Size = new System.Drawing.Size(172, 13);
            this.txtTen_CvX.TabIndex = 11;
            this.txtTen_CvX.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtTen_CvX.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_CvX.Value = ((object)(resources.GetObject("txtTen_CvX.Value")));
            // 
            // txtMa_CvX
            // 
            this.txtMa_CvX.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_CvX.CheckTextSearched = false;
            this.txtMa_CvX.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_CvX.EmptyIsValid = true;
            this.txtMa_CvX.FieldDisplay = "Ten_Cv";
            this.txtMa_CvX.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_CvX.Location = new System.Drawing.Point(486, 96);
            this.txtMa_CvX.MaxLength = 32;
            this.txtMa_CvX.Name = "txtMa_CvX";
            this.txtMa_CvX.OldValue = null;
            this.txtMa_CvX.Size = new System.Drawing.Size(118, 20);
            this.txtMa_CvX.TabIndex = 10;
            this.txtMa_CvX.TableName = "DMCV";
            this.txtMa_CvX.TextDisplay = this.txtTen_CvX;
            this.txtMa_CvX.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_CvX.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_CvX.Value = ((object)(resources.GetObject("txtMa_CvX.Value")));
            // 
            // lblMa_Cv
            // 
            this.lblMa_Cv.AutoSize = true;
            this.lblMa_Cv.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Cv.Location = new System.Drawing.Point(409, 99);
            this.lblMa_Cv.Name = "lblMa_Cv";
            this.lblMa_Cv.Size = new System.Drawing.Size(48, 14);
            this.lblMa_Cv.TabIndex = 104;
            this.lblMa_Cv.Text = "Chức vụ";
            // 
            // txtTen_CvN
            // 
            this.txtTen_CvN.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_CvN.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_CvN.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_CvN.CheckTextSearched = false;
            this.txtTen_CvN.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_CvN.Enabled = false;
            this.txtTen_CvN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_CvN.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_CvN.Location = new System.Drawing.Point(610, 122);
            this.txtTen_CvN.Name = "txtTen_CvN";
            this.txtTen_CvN.OldValue = null;
            this.txtTen_CvN.Size = new System.Drawing.Size(172, 13);
            this.txtTen_CvN.TabIndex = 15;
            this.txtTen_CvN.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtTen_CvN.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_CvN.Value = ((object)(resources.GetObject("txtTen_CvN.Value")));
            // 
            // txtMa_CvN
            // 
            this.txtMa_CvN.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_CvN.CheckTextSearched = false;
            this.txtMa_CvN.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_CvN.EmptyIsValid = true;
            this.txtMa_CvN.FieldDisplay = "Ten_Cv";
            this.txtMa_CvN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_CvN.Location = new System.Drawing.Point(486, 118);
            this.txtMa_CvN.MaxLength = 32;
            this.txtMa_CvN.Name = "txtMa_CvN";
            this.txtMa_CvN.OldValue = null;
            this.txtMa_CvN.Size = new System.Drawing.Size(118, 20);
            this.txtMa_CvN.TabIndex = 14;
            this.txtMa_CvN.TableName = "DMCV";
            this.txtMa_CvN.TextDisplay = this.txtTen_CvN;
            this.txtMa_CvN.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_CvN.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_CvN.Value = ((object)(resources.GetObject("txtMa_CvN.Value")));
            // 
            // lblMa_CvN
            // 
            this.lblMa_CvN.AutoSize = true;
            this.lblMa_CvN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_CvN.Location = new System.Drawing.Point(409, 121);
            this.lblMa_CvN.Name = "lblMa_CvN";
            this.lblMa_CvN.Size = new System.Drawing.Size(48, 14);
            this.lblMa_CvN.TabIndex = 115;
            this.lblMa_CvN.Text = "Chức vụ";
            // 
            // txtTen_DtN
            // 
            this.txtTen_DtN.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_DtN.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_DtN.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_DtN.CheckTextSearched = false;
            this.txtTen_DtN.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_DtN.Enabled = false;
            this.txtTen_DtN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_DtN.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_DtN.Location = new System.Drawing.Point(224, 121);
            this.txtTen_DtN.Name = "txtTen_DtN";
            this.txtTen_DtN.OldValue = null;
            this.txtTen_DtN.Size = new System.Drawing.Size(172, 13);
            this.txtTen_DtN.TabIndex = 13;
            this.txtTen_DtN.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtTen_DtN.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_DtN.Value = ((object)(resources.GetObject("txtTen_DtN.Value")));
            // 
            // txtMa_DtN
            // 
            this.txtMa_DtN.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_DtN.CheckTextSearched = false;
            this.txtMa_DtN.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_DtN.EmptyIsValid = true;
            this.txtMa_DtN.FieldDisplay = "Ten_Dt";
            this.txtMa_DtN.FirstFilter = "Is_Stop = \'1\'";
            this.txtMa_DtN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_DtN.Location = new System.Drawing.Point(100, 118);
            this.txtMa_DtN.MaxLength = 32;
            this.txtMa_DtN.Name = "txtMa_DtN";
            this.txtMa_DtN.OldValue = null;
            this.txtMa_DtN.Size = new System.Drawing.Size(118, 20);
            this.txtMa_DtN.TabIndex = 12;
            this.txtMa_DtN.TableName = "DMDT";
            this.txtMa_DtN.TextDisplay = this.txtTen_DtN;
            this.txtMa_DtN.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_DtN.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_DtN.Value = ((object)(resources.GetObject("txtMa_DtN.Value")));
            this.txtMa_DtN.Validated += new System.EventHandler(this.txtMa_DtN_Validated);
            // 
            // lblMa_DtN
            // 
            this.lblMa_DtN.AutoSize = true;
            this.lblMa_DtN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_DtN.Location = new System.Drawing.Point(13, 120);
            this.lblMa_DtN.Name = "lblMa_DtN";
            this.lblMa_DtN.Size = new System.Drawing.Size(84, 14);
            this.lblMa_DtN.TabIndex = 108;
            this.lblMa_DtN.Text = "Người thực hiện";
            // 
            // txtTTien
            // 
            this.txtTTien.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTTien.BackColor = System.Drawing.Color.White;
            this.txtTTien.Enabled = false;
            this.txtTTien.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTTien.ForeColor = System.Drawing.Color.Black;
            this.txtTTien.Location = new System.Drawing.Point(674, 465);
            this.txtTTien.Name = "txtTTien";
            this.txtTTien.NumericValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.txtTTien.OldValue = null;
            this.txtTTien.Size = new System.Drawing.Size(108, 20);
            this.txtTTien.TabIndex = 21;
            this.txtTTien.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtTTien.UserTextNumericFormat = SmartSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.txtTTien.Value = ((object)(resources.GetObject("txtTTien.Value")));
            // 
            // lblTTien_Nt0
            // 
            this.lblTTien_Nt0.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.lblTTien_Nt0.AutoSize = true;
            this.lblTTien_Nt0.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTTien_Nt0.Location = new System.Drawing.Point(617, 468);
            this.lblTTien_Nt0.Name = "lblTTien_Nt0";
            this.lblTTien_Nt0.Size = new System.Drawing.Size(51, 14);
            this.lblTTien_Nt0.TabIndex = 117;
            this.lblTTien_Nt0.Text = "Tổng tiền";
            // 
            // txtTen_BpX
            // 
            this.txtTen_BpX.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_BpX.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_BpX.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_BpX.CheckTextSearched = false;
            this.txtTen_BpX.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_BpX.Enabled = false;
            this.txtTen_BpX.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_BpX.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_BpX.Location = new System.Drawing.Point(222, 78);
            this.txtTen_BpX.Name = "txtTen_BpX";
            this.txtTen_BpX.OldValue = null;
            this.txtTen_BpX.Size = new System.Drawing.Size(559, 13);
            this.txtTen_BpX.TabIndex = 7;
            this.txtTen_BpX.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtTen_BpX.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_BpX.Value = ((object)(resources.GetObject("txtTen_BpX.Value")));
            // 
            // txtMa_BpX
            // 
            this.txtMa_BpX.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_BpX.CheckTextSearched = false;
            this.txtMa_BpX.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_BpX.EmptyIsValid = true;
            this.txtMa_BpX.FieldDisplay = "Ten_Bp";
            this.txtMa_BpX.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_BpX.FoundIsValid = true;
            this.txtMa_BpX.Location = new System.Drawing.Point(100, 74);
            this.txtMa_BpX.MaxLength = 32;
            this.txtMa_BpX.Name = "txtMa_BpX";
            this.txtMa_BpX.OldValue = null;
            this.txtMa_BpX.Size = new System.Drawing.Size(118, 20);
            this.txtMa_BpX.TabIndex = 6;
            this.txtMa_BpX.TableName = "DMBP";
            this.txtMa_BpX.TextDisplay = this.txtTen_BpX;
            this.txtMa_BpX.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_BpX.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_BpX.Value = ((object)(resources.GetObject("txtMa_BpX.Value")));
            // 
            // lblMa_BpX
            // 
            this.lblMa_BpX.AutoSize = true;
            this.lblMa_BpX.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_BpX.Location = new System.Drawing.Point(13, 77);
            this.lblMa_BpX.Name = "lblMa_BpX";
            this.lblMa_BpX.Size = new System.Drawing.Size(47, 14);
            this.lblMa_BpX.TabIndex = 120;
            this.lblMa_BpX.Text = "Bộ phận";
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "Ma_Ts";
            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.BottomLeft;
            this.Column3.DefaultCellStyle = dataGridViewCellStyle1;
            this.Column3.DestinationFields = "Ten_Ts, Dvt";
            this.Column3.DisabledForeColor = System.Drawing.Color.Blue;
            this.Column3.FirstFilter = "Loai_Ts = \'K\'";
            this.Column3.HeaderText = "Mã công cụ";
            this.Column3.MinimumWidth = 100;
            this.Column3.Name = "Column3";
            this.Column3.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column3.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column3.SourceFields = "Ten_Ts, Dvt";
            this.Column3.TableName = "DMTS";
            this.Column3.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.Column3.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "Ten_Ts";
            this.Column4.HeaderText = "Tên công cụ";
            this.Column4.MinimumWidth = 140;
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 171;
            // 
            // Column11
            // 
            this.Column11.DataPropertyName = "Dvt";
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            this.Column11.DefaultCellStyle = dataGridViewCellStyle2;
            this.Column11.DisabledForeColor = System.Drawing.Color.Blue;
            this.Column11.HeaderText = "Đvt";
            this.Column11.MinimumWidth = 60;
            this.Column11.Name = "Column11";
            this.Column11.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column11.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column11.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.Column11.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.Column11.Width = 60;
            // 
            // Column23
            // 
            this.Column23.DataPropertyName = "Ghi_Chu";
            this.Column23.HeaderText = "Mô tả";
            this.Column23.Name = "Column23";
            this.Column23.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column23.Width = 120;
            // 
            // Column22
            // 
            this.Column22.DataPropertyName = "So_Luong9";
            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column22.DefaultCellStyle = dataGridViewCellStyle3;
            this.Column22.HeaderText = "Số lượng";
            this.Column22.MinimumWidth = 100;
            this.Column22.Name = "Column22";
            this.Column22.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column22.UserTextNumericFormat = SmartSoft.AppInstance.TextNumericFormat.Quantity;
            this.Column22.ZeroIsValid = true;
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Gia";
            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column1.DefaultCellStyle = dataGridViewCellStyle4;
            this.Column1.HeaderText = "Giá";
            this.Column1.Name = "Column1";
            this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column1.UserTextNumericFormat = SmartSoft.AppInstance.TextNumericFormat.LocalPrice;
            this.Column1.ZeroIsValid = true;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "Tien";
            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column2.DefaultCellStyle = dataGridViewCellStyle5;
            this.Column2.HeaderText = "Tiền";
            this.Column2.Name = "Column2";
            this.Column2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column2.UserTextNumericFormat = SmartSoft.AppInstance.TextNumericFormat.LocalAmount;
            this.Column2.ZeroIsValid = true;
            // 
            // FormCCTLEditor
            // 
            this.ClientSize = new System.Drawing.Size(794, 532);
            this.Controls.Add(this.txtTen_BpX);
            this.Controls.Add(this.txtMa_BpX);
            this.Controls.Add(this.lblMa_BpX);
            this.Controls.Add(this.txtTTien);
            this.Controls.Add(this.lblTTien_Nt0);
            this.Controls.Add(this.txtTen_CvN);
            this.Controls.Add(this.txtMa_CvN);
            this.Controls.Add(this.lblMa_CvN);
            this.Controls.Add(this.txtTen_DtN);
            this.Controls.Add(this.txtMa_DtN);
            this.Controls.Add(this.lblMa_DtN);
            this.Controls.Add(this.txtTen_CvX);
            this.Controls.Add(this.txtMa_CvX);
            this.Controls.Add(this.lblMa_Cv);
            this.Controls.Add(this.txtDia_Chi);
            this.Controls.Add(this.txtTen_Dt);
            this.Controls.Add(this.txtMa_Dt);
            this.Controls.Add(this.lblDia_Chi);
            this.Controls.Add(this.lblMa_Dt);
            this.Controls.Add(this.txtDesc_EN);
            this.Controls.Add(this.txtGhi_Chu);
            this.Controls.Add(this.txtDien_Giai);
            this.Controls.Add(this.lblGhi_Chu);
            this.Controls.Add(this.lblDesc_EN);
            this.Controls.Add(this.lblDien_Giai);
            this.Controls.Add(this.grdDetail);
            this.Name = "FormCCTLEditor";
            this.Controls.SetChildIndex(this.grdDetail, 0);
            this.Controls.SetChildIndex(this.lblPhan_Loai, 0);
            this.Controls.SetChildIndex(this.txtSo_Ct, 0);
            this.Controls.SetChildIndex(this.txtNgay_Ps, 0);
            this.Controls.SetChildIndex(this.txtNgay_Ct, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai1, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai2, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai3, 0);
            this.Controls.SetChildIndex(this.lblDien_Giai, 0);
            this.Controls.SetChildIndex(this.lblDesc_EN, 0);
            this.Controls.SetChildIndex(this.lblGhi_Chu, 0);
            this.Controls.SetChildIndex(this.txtDien_Giai, 0);
            this.Controls.SetChildIndex(this.txtGhi_Chu, 0);
            this.Controls.SetChildIndex(this.txtDesc_EN, 0);
            this.Controls.SetChildIndex(this.lblMa_Dt, 0);
            this.Controls.SetChildIndex(this.lblDia_Chi, 0);
            this.Controls.SetChildIndex(this.txtMa_Dt, 0);
            this.Controls.SetChildIndex(this.txtTen_Dt, 0);
            this.Controls.SetChildIndex(this.txtDia_Chi, 0);
            this.Controls.SetChildIndex(this.lblMa_Cv, 0);
            this.Controls.SetChildIndex(this.txtMa_CvX, 0);
            this.Controls.SetChildIndex(this.txtTen_CvX, 0);
            this.Controls.SetChildIndex(this.lblMa_DtN, 0);
            this.Controls.SetChildIndex(this.txtMa_DtN, 0);
            this.Controls.SetChildIndex(this.txtTen_DtN, 0);
            this.Controls.SetChildIndex(this.lblMa_CvN, 0);
            this.Controls.SetChildIndex(this.txtMa_CvN, 0);
            this.Controls.SetChildIndex(this.txtTen_CvN, 0);
            this.Controls.SetChildIndex(this.lblTTien_Nt0, 0);
            this.Controls.SetChildIndex(this.txtTTien, 0);
            this.Controls.SetChildIndex(this.lblMa_BpX, 0);
            this.Controls.SetChildIndex(this.txtMa_BpX, 0);
            this.Controls.SetChildIndex(this.txtTen_BpX, 0);
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        internal override void OnAdd()
        {
            object obj2 = base.LocalMasterRow["So_Ct"];
            base.LocalMasterRow = base.MakeMasterRow();
            base.LocalMasterRow["Nh_Ct"] = base.SSInvoiceParameters.InvoiceType;
            base.LocalMasterRow["So_Ct"] = this.oMethod.Cong_So_Ct(AppInstance.Subsidiary, base.InvoiceCode, base.LocalMasterRow["Ngay_Ct"], obj2);
            base.MakeDetailTable();
            base.LocalDetailTable.Rows[0]["Stt_Nv"] = 1;
            base.LocalDetailTable.Rows[0]["He_So9"] = 1;
            base.LocalDetailTable.Rows[0]["So_Luong9"] = 0;
            base.LocalDetailTable.Rows[0]["So_Luong"] = 0;
            base.LocalDetailTable.Rows[0]["Gia"] = 0;
            base.LocalDetailTable.Rows[0]["Tien"] = 0;
            base.LocalDetailTable.Rows[0]["H_Luong"] = 0;
            base.LocalDetailTable.Rows[0]["Do_Am_PT"] = 0;
            base.LocalDetailTable.Rows[0]["Do_Con_PT"] = 0;
            base.OnAdd();
        }

        internal override void OnCopy()
        {
            object obj2 = base.LocalMasterRow["So_Ct"];
            base.LocalMasterRow["So_Ct"] = this.oMethod.Cong_So_Ct(AppInstance.Subsidiary, base.InvoiceCode, base.LocalMasterRow["Ngay_Ct"], obj2);
            base.OnCopy();
        }

        internal override void OnResetControls()
        {
            base.DetailGridBrowser = this.grdDetail;
            int num = 0;
            if (!base.SSInvoiceParameters.BilingualUsed)
            {
                this.lblDesc_EN.Visible = false;
                this.txtDesc_EN.Visible = false;
                this.txtDien_Giai.Width = (this.txtDesc_EN.Left + this.txtDesc_EN.Width) - this.txtDien_Giai.Left;
                this.txtDien_Giai.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            }
            //if (!AppInstance.LocationCtrl)
            //{
            //    base.DetailGridBrowser.Columns[6].Visible = false;
            //}
            //if (!AppInstance.LotNumberCtrl)
            //{
            //    base.DetailGridBrowser.Columns[7].Visible = false;
            //}
            //if (!AppInstance.DeadLineCtrl)
            //{
            //    base.DetailGridBrowser.Columns[8].Visible = false;
            //}
            //if (!AppInstance.QualityCtrl)
            //{
            //    base.DetailGridBrowser.Columns[9].Visible = false;
            //}
            //if (!AppInstance.DampCtrl)
            //{
            //    base.DetailGridBrowser.Columns[10].Visible = false;
            //}
            //if (!AppInstance.AlcoholCtrl)
            //{
            //    base.DetailGridBrowser.Columns[11].Visible = false;
            //}
            //if (!AppInstance.LocationCtrl || (base.InvoiceCode != "PWDC"))
            //{
            //    base.DetailGridBrowser.Columns[12].Visible = false;
            //}

            //if (!AppInstance.LocationCtrl)
            //{
            //    base.DetailGridBrowser.Columns[4].Visible = false;
            //}
            //if (!AppInstance.LotNumberCtrl)
            //{
            //    base.DetailGridBrowser.Columns[5].Visible = false;
            //}
            //if (!AppInstance.DeadLineCtrl)
            //{
            //    base.DetailGridBrowser.Columns[6].Visible = false;
            //}
            //if (!AppInstance.QualityCtrl)
            //{
            //    base.DetailGridBrowser.Columns[7].Visible = false;
            //}
            //if (!AppInstance.DampCtrl)
            //{
            //    base.DetailGridBrowser.Columns[8].Visible = false;
            //}
            //if (!AppInstance.AlcoholCtrl)
            //{
            //    base.DetailGridBrowser.Columns[9].Visible = false;
            //}
            //if (!AppInstance.LocationCtrl || (base.InvoiceCode != "PWDC"))
            //{
            //    base.DetailGridBrowser.Columns[10].Visible = false;
            //}
            //if (base.SSInvoiceParameters.FreeFields <= 0)
            //{
            //    num = base.txtMa_Loai1.Top - this.txtGhi_Chu.Top;
                //this.lblMa_KhoN.Top += num;
                //this.txtMa_KhoN.Top += num;
                //this.txtTen_KhoN.Top += num;
            //    this.lblGhi_Chu.Top += num;
            //    this.txtGhi_Chu.Top += num;
            //    base.DetailGridBrowser.Height += num;
            //}
            //if (base.InvoiceCode != "PWDC")
            //{
            //    num = this.txtGhi_Chu.Top - this.txtMa_KhoN.Top;
            //    this.lblMa_KhoN.Visible = false;
            //    this.txtMa_KhoN.Visible = false;
            //    this.txtTen_KhoN.Visible = false;
            //    base.DetailGridBrowser.Height += num;
            //}
            if (base.SSInvoiceParameters.InvoiceType == "2")
            {
                //(base.DetailGridBrowser.Columns[7] as SearchLotNumberColumn).TableName = "LOHANG";
                //base.DetailGridBrowser.Columns[8].ReadOnly = true;
                //base.DetailGridBrowser.Columns[9].ReadOnly = true;
                //base.DetailGridBrowser.Columns[10].ReadOnly = true;
                //base.DetailGridBrowser.Columns[11].ReadOnly = true;

                //(base.DetailGridBrowser.Columns[5] as SearchLotNumberColumn).TableName = "LOHANG";
                //base.DetailGridBrowser.Columns[6].ReadOnly = true;
                //base.DetailGridBrowser.Columns[7].ReadOnly = true;
                //base.DetailGridBrowser.Columns[8].ReadOnly = true;
                //base.DetailGridBrowser.Columns[9].ReadOnly = true;
            }
            else
            {
                //(base.DetailGridBrowser.Columns[7] as SearchLotNumberColumn).TableName = "";
                //(base.DetailGridBrowser.Columns[5] as SearchLotNumberColumn).TableName = "";
            }
            base.OnResetControls();
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            //if (this.txtOng_Ba != null)
            //{
            //    //int num = base.ClientSize.Width - 0xcb;
            //    //this.txtOng_Ba.Width = num / 2;
            //    //this.txtDia_Chi.Left = (this.txtOng_Ba.Left + this.txtOng_Ba.Width) + 0x5c;
            //    //this.txtDia_Chi.Width = num - this.txtOng_Ba.Width;
            //    //this.lblDia_Chi.Left = (this.txtDia_Chi.Left - this.lblDia_Chi.Width) - 6;
            //    if ((base.SSInvoiceParameters != null) && base.SSInvoiceParameters.BilingualUsed)
            //    {
            //        //this.txtDien_Giai.Width = this.txtOng_Ba.Width;
            //        this.txtDesc_EN.Left = this.txtDia_Chi.Left;
            //        this.txtDesc_EN.Width = this.txtDia_Chi.Width;
            //        this.lblDesc_EN.Left = (this.txtDesc_EN.Left - this.lblDesc_EN.Width) - 6;
            //    }
            //}
        }

        protected override bool OnSave()
        {
            if (base.txtNgay_Ps.Value == SDBNull.Value)
            {
                MessageBox.Show("Chưa nhập ngày phát sinh!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.txtNgay_Ct.Value == SDBNull.Value)
            {
                MessageBox.Show("Chưa nhập ngày chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (((DateTime) base.txtNgay_Ct.Value) < AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Ngày chứng từ phải từ ngày " + AppInstance.OpeningDateOfSubEnterprice.ToShortDateString(), AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (((DateTime) base.txtNgay_Ct.Value) <= AppInstance.EndingDateOfSubEnterprice)
            {
                MessageBox.Show("Ngày chứng từ phải từ ngày " + AppInstance.EndingDateOfSubEnterprice.AddDays(1.0).ToShortDateString(), AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            foreach (DataRow row in base.LocalDetailTable.Rows)
            {
                if ((row.RowState != DataRowState.Deleted) && string.IsNullOrEmpty(row["Ma_Ts"].ToString()))
                {
                    MessageBox.Show("Không được để mã công cụ trống!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return false;
                }
            }
            if (!base.CheckNewRow)
            {
                int num = this.oMethod.CheckInvoiceStatus(AppInstance.Subsidiary, AppInstance.UserName, base.SavedMasterOrder);
                switch (num)
                {
                    case 9:
                    case 7:
                        break;

                    default:
                        if ((base.SSInvoiceParameters.AllowPostInvoice && base.SSInvoiceParameters.AllowLockInvoice) || ((num != 6) && (num != 5)))
                        {
                            if (num == 8)
                            {
                                base.SSInvoiceParameters.ShowInvoiceUsed(base.SavedMasterOrder, base.SSInvoiceParameters.StatusMessage(num));
                                return false;
                            }
                            goto Label_01F4;
                        }
                        break;
                }
                MessageBox.Show(base.SSInvoiceParameters.StatusMessage(num), AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
        Label_01F4:
            if (this.oMethod.NumberExisted(AppInstance.Subsidiary, base.CheckNewRow, base.SavedMasterOrder, base.InvoiceCode, base.txtNgay_Ct.Value, base.txtSo_Ct.Value) && (MessageBox.Show("Số chứng từ đã tồn tại. C\x00f3 tiếp tục không?", AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No))
            {
                if (MessageBox.Show("Có muốn tự động tạo số chứng từ không?", AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return false;
                }
                object obj2 = base.txtSo_Ct.Value;
                base.txtSo_Ct.Value = this.oMethod.Cong_So_Ct(AppInstance.Subsidiary, base.InvoiceCode, base.LocalMasterRow["Ngay_Ct"], obj2);
            }
            base.DetailGridBrowser.EndEdit();
            base.LocalMasterRow["Ngay_Ps"] = base.txtNgay_Ps.Value;
            base.LocalMasterRow["Ngay_Ct"] = base.txtNgay_Ct.Value;
            base.LocalMasterRow["So_Ct"] = base.txtSo_Ct.Value;
            base.LocalMasterRow["Ma_BpX"] = this.txtMa_BpX.Value;
            base.LocalMasterRow["Ten_BpX"] = this.txtTen_BpX.Value;         
            base.LocalMasterRow["Ma_Dt"] = this.txtMa_Dt.Value;
            base.LocalMasterRow["Ten_Dt"] = this.txtTen_Dt.Value;
            base.LocalMasterRow["Ma_CvX"] = this.txtMa_CvX.Value;
            base.LocalMasterRow["Ten_CvX"] = this.txtTen_CvX.Value;
            base.LocalMasterRow["Dia_Chi"] = this.txtDia_Chi.Value;
            base.LocalMasterRow["Dien_Giai"] = this.txtDien_Giai.Value;
            base.LocalMasterRow["Desc_EN"] = this.txtDesc_EN.Value;
            base.LocalMasterRow["Ma_DtN"] = this.txtMa_DtN.Value;
            base.LocalMasterRow["Ten_DtN"] = this.txtTen_DtN.Value;
            base.LocalMasterRow["Ma_CvN"] = this.txtMa_CvN.Value;
            base.LocalMasterRow["Ten_CvN"] = this.txtTen_CvN.Value;
            base.LocalMasterRow["TTien"] = this.txtTTien.Value;
            base.LocalMasterRow["Ghi_Chu"] = this.txtGhi_Chu.Value;
            base.LocalMasterRow["Ma_Loai1"] = base.txtMa_Loai1.Value;
            base.LocalMasterRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            base.LocalMasterRow["Ma_Loai3"] = base.txtMa_Loai3.Value;
            return (this.oMethod.Save(base.SSInvoiceParameters.InvoiceHistory, base.CheckNewRow, AppInstance.Subsidiary, AppInstance.UserName, base.LocalMasterRow, base.LocalDetailTable) && base.OnSave());
        }

        internal override void OnShow()
        {
            base.OnShow();
            this.txtMa_Dt.Value = base.LocalMasterRow["Ma_Dt"];
            this.txtTen_Dt.Value = base.LocalMasterRow["Ten_Dt"];
            this.txtMa_CvX.Value = base.LocalMasterRow["Ma_CvX"];
            this.txtTen_CvX.Value = base.LocalMasterRow["Ten_CvX"];
            this.txtMa_BpX.Value = base.LocalMasterRow["Ma_BpX"];
            this.txtTen_BpX.Value = base.LocalMasterRow["Ten_BpX"];

            this.txtDia_Chi.Value = base.LocalMasterRow["Dia_Chi"];
            this.txtDien_Giai.Value = base.LocalMasterRow["Dien_Giai"];
            this.txtDesc_EN.Value = base.LocalMasterRow["Desc_EN"];
            this.txtMa_DtN.Value = base.LocalMasterRow["Ma_DtN"];
            this.txtTen_DtN.Value = base.LocalMasterRow["Ten_DtN"];
            this.txtMa_CvN.Value = base.LocalMasterRow["Ma_CvN"];
            this.txtTen_CvN.Value = base.LocalMasterRow["Ten_CvN"];
            this.txtTTien.Value = base.LocalMasterRow["TTien"];
            this.txtGhi_Chu.Value = base.LocalMasterRow["Ghi_Chu"];
        }
        private bool Sum()
        {
            decimal num = 0;
            foreach (DataRow row in base.LocalDetailTable.Rows)
            {
                if (row.RowState != DataRowState.Deleted)
                {
                    num += (decimal)row["Tien"];
                }
            }
            base.LocalMasterRow["TTien"] = num;
            this.txtTTien.Value = num;
            return true;
        }
        private void SetItemRatio()
        {
            DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
            DataRow row2 = SSDataAccess.SelectDataRow(false, "DMVT", "Ma_Vt", row["Ma_Vt"].ToString(), null);
            if (row2 != null)
            {
                if (row["Dvt"].Equals(row2["Dvt"]))
                {
                    row["He_So9"] = 1;
                }
                else if (row["Dvt"].Equals(row2["Dvt0"]))
                {
                    row["He_So9"] = row2["He_So0"];
                }
                else if (row["Dvt"].Equals(row2["Dvt1"]))
                {
                    row["He_So9"] = row2["He_So1"];
                }
                else if (row["Dvt"].Equals(row2["Dvt2"]))
                {
                    row["He_So9"] = row2["He_So2"];
                }
                row.EndEdit();
                this.Calculate();
            }
        }

        private void SetItemUnits()
        {
            DataRow row = ((DataRowView) base.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
            DataRow row2 = SSDataAccess.SelectDataRow(false, "DMVT", "Ma_Vt", row["Ma_Vt"].ToString(), null);
            if (row2 != null)
            {
                if (string.IsNullOrEmpty(row2["Dvt0"].ToString()))
                {
                    base.DetailGridBrowser.CurrentCell.ReadOnly = true;
                }
                else
                {
                    string str = (string.IsNullOrEmpty(row2["Dvt"].ToString()) ? "" : row2["Dvt"].ToString()) + (string.IsNullOrEmpty(row2["Dvt0"].ToString()) ? "" : ("," + row2["Dvt0"].ToString())) + (string.IsNullOrEmpty(row2["Dvt1"].ToString()) ? "" : ("," + row2["Dvt1"].ToString())) + (string.IsNullOrEmpty(row2["Dvt2"].ToString()) ? "" : ("," + row2["Dvt2"].ToString())) + (string.IsNullOrEmpty(row2["Dvt3"].ToString()) ? "" : ("," + row2["Dvt3"].ToString()));
                    (base.DetailGridBrowser.CurrentCell as OptionCell).InputMask = str;
                    base.DetailGridBrowser.CurrentCell.ReadOnly = false;
                }
            }
        }

        private void txtMa_Dt_Validated(object sender, EventArgs e)
        {
            if (this.txtMa_Dt.ValueChanged)
            {
                //this.txtOng_Ba.Value = this.txtMa_Dt.GetFieldData("Doi_Tac").Equals(DBNull.Value) ? this.txtTen_Dt.Value : this.txtMa_Dt.GetFieldData("Doi_Tac");
                this.txtDia_Chi.Value = this.txtMa_Dt.GetFieldData("Dia_Chi");
                this.txtMa_CvX.Value = this.txtMa_Dt.GetFieldData("Ma_Cv");
            }
        }

        private void txtMa_DtN_Validated(object sender, EventArgs e)
        {
            if (this.txtMa_DtN.ValueChanged)
            {
                this.txtMa_CvN.Value = this.txtMa_DtN.GetFieldData("Ma_Cv");
            }
        }

    }
}

